import { defineStore } from "pinia";
import { Get_admin_info, get_total } from "@/apis/web/WebApi"
import { type Admin } from "@/types/WebEssay"
import { onMounted, reactive } from "vue"
const UserStore = defineStore('user', () => {
    onMounted(async () => {
        await getData()
    })
    const total = reactive<any>({
        "essay_count": [
            {
                "_id": "",
                "count": 0
            },
            {
                "_id": "",
                "count": 0
            }
        ],
        "speak_count": 0
    })
    const admin_info = reactive<Admin>({
        avatar: '',
        bilibili: '',
        csdn: '',
        famous_sentence: '',
        gitee: '',
        introduce: '',
        qq: '',
        role: '',
        tags: [],
        username: '',
        _id: ''

    })
    const getData = async () => {
        const result = await Get_admin_info()
        const result2 = await get_total()
        Object.assign(admin_info, result.data)
        if (result2.data.essay_count.length !== 2) {

        } else {
            Object.assign(total, result2.data)
        }



    }

    return {
        total,
        admin_info,
        getData
    }
})



export default UserStore